<template>
  <DataList :cate="cate" :cols="cols" skipExcelNumber="2" :excelHeader="excelHeader" :groupCheck = "groupCheck" :name="name"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import linq from "linq"
import {
  addJfsrmx2,
  deleteJfsrmx2,
  updateJfsrmx2,
  getJfsrmx2,
  bulkAddJfsrmx2
} from "@/api/财政经常性补助收入.js";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A5-1-2财政经常性补助收入",
      name:'5.1.2 财政经常性补助收入',
      excelHeader: {
        B3: "项目名称",
        C3: "标准（万元）",
        D3: "项目金额（万元）"
      },
      cols: [
        { label: "项目名称(全称)", prop: "CZJCXBZXMMC" },
        { label: "标准(万元)", prop: "CZJCXBZBZ" },
        { label: "项目金额(万元)", prop: "CZJCXBZXMJE" }
      ],
      groupCheck:[{data:["CZJCXBZXMMC","CZJCXBZBZ","CZJCXBZXMJE"],desc:'请完善输入'}]
    };
  },
  methods: {
    getSummaries(list){
        const sums = [];
          this.cols.forEach((column, index) => {
            sums[index]="";
          });
          sums[0]="合计";
          sums[6]= "项目数:"+linq.from(list).distinct("$.CZJCXBZXMMC").count()
          sums[7]= "合计:"+linq.from(list).sum("$.CZJCXBZXMJE").toFixed(2)
          sums[9]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
          sums[9] += ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
          sums[9] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
        return sums; 
    },
    check(array, list) {
      return new Promise(async (resolve, reject) => {
        try {
          var user = getUser();

          resolve();
        } catch (e) {
          reject(e);
        }
      });
    },
    async fetchData() {
      var user = getUser();
      var datas = await getJfsrmx2(user.XXID, user.CJPC);
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model));
      return new Promise(async (resolve, reject) => {
        this.check(reject, temp);

        console.log(JSON.stringify(temp));
        var model = await addJfsrmx2(temp);
        resolve(model);
      });
    },
    async  bulkAdd(array){
       await  bulkAddJfsrmx2({Jfsrmx2:array});
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model));
      return new Promise(async (resolve, reject) => {
        this.check(reject, temp);
        console.log(JSON.stringify(temp));
        var model = await updateJfsrmx2(temp);
        resolve(model);
      });
      //
    },
    ondelete(model) {
      var temp = JSON.parse(JSON.stringify(model));
      return new Promise(async (resolve, reject) => {
        await deleteJfsrmx2(temp);
        resolve();
      });
    }
  }
};
</script>
<style>
</style>